#!/usr/bin/env python

import sys, time
from daemon import Daemon
from consciusdaemon import ConsciusDaemon

global debug

if __name__ == "__main__":
	daemon = ConsciusDaemon('/tmp/consciusd.pid')
	
	if len(sys.argv) == 2:
		if 'start' == sys.argv[1]:
			daemon.start()
		elif 'stop' == sys.argv[1]:
			daemon.stop()
		elif 'debug' == sys.argv[1]:
			daemon.debug()
		elif 'restart' == sys.argv[1]:
			daemon.restart()
		else:
			print "Unknown command"
			sys.exit(2)
		
		sys.exit(0)
		
	else:
		print "usage: %s start|stop|debug|restart" % sys.argv[0]
		print ""
		print "start - launches the daemon in the background"
		print "stop - stop the daemon if it was launched"
		print "debug - launches the daemon in the foreground for debugging purposes"
		print "restart - stops and starts the daemon in background mode"
		
		sys.exit(2)
